package com.wc.算法提高课.B第二章_搜索.Astar.八数码;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/25 20:13
 * @description https://www.acwing.com/problem/content/description/181/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static String start = "", end = "";
    static PriorityQueue<Pair> q = new PriorityQueue<>();
    static Map<String, Integer> dist = new HashMap<>();
    static Map<String, String[]> prev = new HashMap<>();

    public static void main(String[] args) {
        String state = "";
        for (int i = 1; i <= 9; i++) {
            String c = sc.next();
            start += c;
            if (!c.equals("x")) state += c;
        }

        end = "12345678x";
        int cnt = 0;
        for (int i = 0; i < 8; i++) {
            for (int j = i; j < 8; j++) {
                if (state.charAt(i) > state.charAt(j)) cnt++;
            }
        }
        if ((cnt & 1) == 1) out.println("unsolvable");
        else {
            bfs(start);
            StringBuffer res = new StringBuffer();
            while (!end.equals(start))
            {
                String[] t = prev.get(end);
                res.append(t[0]);
                end = t[1];
            }
            res.reverse();
            out.println(res);
        }
        out.flush();
    }

    static void bfs(String start) {
        q.add(new Pair(start, f(start)));
        dist.put(start, 0);
        int[] dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
        char[] op = "udlr".toCharArray();
        while (!q.isEmpty()) {
            Pair t = q.poll();
            String state = t.x;
            if (state.equals(end)) break;
            int d = t.y;
            // find x
            int x = 0, y = 0;
            for (int i = 0; i < 9; i++) {
                if (state.charAt(i) == 'x') {
                    x = i / 3;
                    y = i % 3;
                    break;
                }
            }
            String source = state;
            for (int i = 0; i < 4; i++) {
                int a = x + dx[i], b = y + dy[i];
                if (a < 0 || a > 2 || b < 0 || b > 2) continue;
                state = swap(source.toCharArray(), a * 3 + b, x * 3 + y);
                if (!dist.containsKey(state) || dist.get(source) + 1 < dist.get(state)) {
                    dist.put(state, dist.get(source) + 1);
                    prev.put(state, new String[]{"" + op[i], source});
                    q.add(new Pair(state, dist.get(source) + 1 + f(state)));
                }
            }
        }
    }

    // 曼哈顿距离
    static int f(String state) {
        int dist = 0;
        for (int i = 0; i < 9; i++) {
            if (state.charAt(i) - '1' != i) {
                int num = state.charAt(i) - '1';
                int x = num / 3, y = num % 3;
                dist += Math.abs(x - i / 3) + Math.abs(y - i % 3);
            }
        }
        return dist;
    }

    static String swap(char[] cs, int i, int j) {
        char tmp = cs[i];
        cs[i] = cs[j];
        cs[j] = tmp;
        return new String(cs);
    }

    static class Pair implements Comparable<Pair> {
        String x;
        int y;

        Pair(String x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Pair o) {
            return y - o.y;
        }
    }

}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
